package day06;
import java.util.Scanner;
import java.util.Arrays;
public class Practice01 {
    //1. 猜数字
    //2. 生成验证码
    //3. 素数
    //4. 计算机票折后价格
    //5. 计算总分和平均分
    public static void main(String[] args) {
        /** 猜数字 */
        Scanner scan = new Scanner(System.in);
        int sum1 = (int) (Math.random() * 100 + 1);
        System.out.println("猜个数字");
        System.out.println(sum1);
        while (true) {
            System.out.println("猜猜看");
            int sum2 = scan.nextInt();
            if (sum2 > sum1) {
                System.out.println("猜大了");
            } else if (sum2 < sum1) {
                System.out.println("猜小了");
            } else {
                System.out.println("猜对了");
                break;
            }
        }
        //输出验证码
        String code = veriCode(4);
        System.out.println(code);
        //素数
        pNum();
        //机票
        Scanner in = new Scanner(System.in);
        System.out.println("输入票价：");
        double price1 = in.nextDouble();
        System.out.println("选择舱位：1.A类 2.B类 3.C类");
        int type1 = in.nextInt();
        System.out.println("选择月份：");
        int mon = in.nextInt();
        double finalAirPrice= airPrice(price1,type1,mon);
        if(finalAirPrice>0){
        System.out.println("最终票价为："+finalAirPrice);
        }
        //计算总分和平均分
        double[]score = new double[5];
        for(int c =0;c<5;c++){
            System.out.println("请第"+(c+1)+"位评委打分");
             score[c] = in.nextDouble();
        }
             double totalScore=totalSc(score);
             double avgScore=avgSc(score);
            System.out.println("总分："+totalScore);
            System.out.println("平均分："+avgScore);
        }

    /**
     * 生成验证码
     */
    public static String veriCode(int leng) {
        String code = "";
        char[] aa = {
                'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p'
                , 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z', 'A', 'B', 'C', 'D', 'E', 'F', 'G'
                , 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y',
                'Z', '0', '1', '2', '3', '4', '5', '6', '7', '8', '9'
        };
        for (int i = 0; i < leng; i++) {
            int bb = (int) (Math.random() * aa.length);
            code += aa[bb];
        }
        return code;
    }

    /**
     * 素数 2到200
     */
    public static void pNum() {
        for (int i = 2; i <= 200; i++) {
            boolean flag = true;
            for (int j = 2; j < i / 2; j++) {
                if (i % j == 0) {
                    flag = false;
                }
            }
            if (flag) {
                System.out.println(i + "是素数");
            }
        }
    }

    /**
     * 机票
     */
    public static double airPrice(double price, int ty, int mon) {
        double airPrice1=price;
        if (mon < 1 || mon > 12) {
            System.out.println("月份输入错误");
            return -1;
        }
        if (ty < 1 || ty > 3) {
            System.out.println("舱位输入错误");
            return -1;
        }
        if (mon >=6 && mon <=11) {
            switch (ty) {
                case 1:
                    airPrice1 = price * 0.9;
                    break;
                case 2:
                    airPrice1 = price * 0.8;
                    break;
                case 3:
                    airPrice1 = price * 0.7;
                    break;
            }
        } else {
            switch (ty) {
                case 1:
                  airPrice1 = price * 0.8;
                    break;
                case 2:
                    airPrice1 = price * 0.75;
                    break;
                case 3:
                    airPrice1 = price * 0.65;
                    break;
            }
        }
        return airPrice1;
    }
    /** 计算总分和平均分 */
    public static double totalSc(double[]score){
        double sum =0;
        for(int i =0;i<score.length;i++){
            sum+=score[i];
        }
        Arrays.sort(score);
        double totalScore=sum-score[0]-score[score.length-1];
        return  totalScore;
    }
    public static double avgSc(double[]score){
        double toSc=totalSc(score);
        double avgScore= toSc/(score.length-2);
        return  avgScore;
    }
}
